/*******************************************************************************
 * $Header: /cvsroot/oloa/org.gocom.bpm.platform.model/src/org/gocom/bpm/platform/model/web/taglib/ActivityGraphTag.java,v 1.1 2011/07/03 02:30:16 hufulai Exp $
 * $Revision: 1.1 $
 * $Date: 2011/07/03 02:30:16 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2010-5-26
 *******************************************************************************/

package com.atozsoft.wf.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.eos.web.taglib.util.XpathUtil;


public class ActivityGraphTag extends WFHTMLBaseTag
{
    public static final long serialVersionUID = 0xf4ba3e19f2b35b79L;
    private String activityType;
    private String activityName;
    private String title;
    private String icon;


    public ActivityGraphTag()
    {
        activityType = null;
        activityName = null;
        title = null;
        icon = null;
    }

    public void initVariables()
    {
        try
        {
            setActivityType(XpathUtil.getStringByXpathSupport(getRootObj(), getActivityType()));
            setActivityName(XpathUtil.getStringByXpathSupport(getRootObj(), getActivityName()));
            setTitle(XpathUtil.getStringByXpathSupport(getRootObj(), getTitle()));
            setIcon(XpathUtil.getStringByXpathSupport(getRootObj(), getIcon()));
            setOnclick(XpathUtil.getStringByXpathSupport(getRootObj(), getOnclick()));
            setOndblclick(XpathUtil.getStringByXpathSupport(getRootObj(), getOndblclick()));
            setOnmouseover(XpathUtil.getStringByXpathSupport(getRootObj(), getOnmouseover()));
            setOnmouseout(XpathUtil.getStringByXpathSupport(getRootObj(), getOnmouseout()));
        }
        catch(JspException e)
        {
            e.printStackTrace();
        }
    }

    public int doStartTag()
        throws JspException
    {
        initScope();
        initVariables();
        ProcessGraphTag processGraphTag = (ProcessGraphTag)TagSupport.findAncestorWithClass(this, ProcessGraphTag.class);
        State state = processGraphTag.getGraphics().getNextState();
        if(state != null && getActivityType().equals(state.getType()))
            if(getActivityName() != null && getActivityName().length() > 0)
            {
                if(getActivityName().equals(state.getName()))
                {
                    processGraphTag.assembleMouseEvents(this, state);
                    if(getIcon() != null && getIcon().length() > 0)
                        state.setImgSrc(getIcon());
                    if(getTitle() != null && getTitle().length() > 0)
                        state.setName(getTitle());
                }
            } else
            {
                processGraphTag.assembleMouseEvents(this, state);
                if(getIcon() != null && getIcon().length() > 0)
                    state.setImgSrc(getIcon());
                if(getTitle() != null && getTitle().length() > 0)
                    state.setName(getTitle());
            }
        return 1;
    }

    public String getActivityType()
    {
        return activityType;
    }

    public void setActivityType(String activityType)
    {
        this.activityType = activityType;
    }

    public String getIcon()
    {
        return icon;
    }

    public void setIcon(String icon)
    {
        this.icon = icon;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getActivityName()
    {
        return activityName;
    }

    public void setActivityName(String activityName)
    {
        this.activityName = activityName;
    }

//    public void validate()
//    {
//        IValidator validator = AssemblyValidator.getInstance();
//        try
//        {
//            validator.validate(this, 0xf4ba3e19f2b35b79L);
//        }
//        catch(DataValidateException e)
//        {
//            if(logger.isErrorEnabled())
//                logger.log(40000, e);
//            e.printStackTrace();
//        }
//    }

    public void release()
    {
        super.release();
        activityType = null;
        activityName = null;
        title = null;
        icon = null;
    }

}
